// 用户管理相关API - 纯前端模拟数据

// 模拟用户数据
const mockUsers = [
  {
    id: 1,
    name: '张三',
    username: 'zhangsan',
    role: '主唱',
    accountRole: 'user',
    accountStatus: 'active',
    avatar: 'https://joeschmoe.io/api/v1/1',
    email: 'zhangsan@example.com',
    lastLogin: '2024-01-18 14:30',
    loginCount: 45,
  },
  {
    id: 2,
    name: '李四',
    username: 'lisi',
    role: '吉他手',
    accountRole: 'admin',
    accountStatus: 'active',
    avatar: 'https://joeschmoe.io/api/v1/2',
    email: 'lisi@example.com',
    lastLogin: '2024-01-19 09:15',
    loginCount: 128,
  },
  {
    id: 3,
    name: '王五',
    username: 'wangwu',
    role: '贝斯手',
    accountRole: 'user',
    accountStatus: 'inactive',
    avatar: 'https://joeschmoe.io/api/v1/3',
    email: 'wangwu@example.com',
    lastLogin: '2024-01-10 16:45',
    loginCount: 23,
  },
];

// 模拟API响应
const mockApiResponse = (data, delay = 300) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve({ data });
    }, delay);
  });
};

// 获取用户列表
export const getUsers = async (params) => {
  return mockApiResponse({
    success: true,
    data: mockUsers,
    total: mockUsers.length,
  });
};

// 根据ID获取用户
export const getUserById = async (id) => {
  const user = mockUsers.find(u => u.id === parseInt(id));
  return mockApiResponse({
    success: true,
    data: user,
  });
};

// 创建用户
export const createUser = async (data) => {
  const newUser = {
    id: Date.now(),
    ...data,
    lastLogin: new Date().toLocaleString('zh-CN'),
    loginCount: 0,
  };
  mockUsers.push(newUser);
  
  return mockApiResponse({
    success: true,
    data: newUser,
    message: '用户创建成功',
  });
};

// 更新用户
export const updateUser = async (id, data) => {
  const index = mockUsers.findIndex(u => u.id === parseInt(id));
  if (index !== -1) {
    mockUsers[index] = { ...mockUsers[index], ...data };
  }
  
  return mockApiResponse({
    success: true,
    message: '用户更新成功',
  });
};

// 删除用户
export const deleteUser = async (id) => {
  const index = mockUsers.findIndex(u => u.id === parseInt(id));
  if (index !== -1) {
    mockUsers.splice(index, 1);
  }
  
  return mockApiResponse({
    success: true,
    message: '用户删除成功',
  });
};

// 重置密码
export const resetPassword = async (id) => {
  return mockApiResponse({
    success: true,
    message: '密码重置成功',
  });
};

// 批量操作
export const batchOperation = async (userIds, action) => {
  return mockApiResponse({
    success: true,
    message: `批量${action}操作成功`,
  });
}; 